﻿using System;
using System.Collections.Generic;
using System.Text;
using ELooker.utils;

namespace ELooker.vlcWrapper
{
    class VLC
    {
        public static VLC[] VLCs = null; 
        private int _id=0;
        private IntPtr _libvlcInstance;
        private IntPtr _libvlcMediaPlayer;
        private IntPtr _myPlayer;       //本次播放实例

        public IntPtr MyPlayer
        {
            get { return _myPlayer; }
        }

        public IntPtr LibvlcMediaPlayer
        {
            get { return _libvlcMediaPlayer; }
        }
        

        public VLC(string[] argv)
        {
            _libvlcInstance = VLC_API.libvlc_new(argv.Length, argv);
            _libvlcMediaPlayer = VLC_API.libvlc_media_player_new(_libvlcInstance);
        }

        public void setRenderWindow(int handler)
        {
            VLC_API.libvlc_media_player_set_hwnd(_libvlcMediaPlayer, handler);
        }

        public void openMedia(string url,Boolean autoPlay=true)
        {
            _myPlayer = VLC_API.libvlc_media_new_path(_libvlcInstance, url);
            VLC_API.libvlc_media_player_set_media(_libvlcMediaPlayer, _myPlayer);

            if (autoPlay)
            {
                play();
            }

            //VLC_API.libvlc_media_release(_myPlayer);
        }

        public void play()
        {
            VLC_API.libvlc_media_player_play(_libvlcMediaPlayer);
            
        }

        public void dispose()
        {
            VLC_API.libvlc_release(_libvlcInstance);
        }

    }
}
